import Vue from "vue";
import VueRouter from "vue-router";

const oranigelRouter = VueRouter.prototype.push;
VueRouter.prototype.push = function push(load) {
    return oranigelRouter.call(this, load).catch(err => {
        err
    })
}


Vue.use(VueRouter);

const login = () => import("@/views/login/main");
const index = () => import("@/views/index/main");
const page404 = () => import("@/views/404");
const chart = () => import("@/components/charts/chart");


// 用户 子组件
const profile = () => import("@/views/user/profile");
const setUser = () => import("@/views/user/setUser");

// 权限路由
const admin = () => import("@/views/admin");

// 品牌子组件
const shoplist = () => import("@/views/brand/shoplist")
const setshop = () => import("@/views/brand/setshop")

export const asyncRoutes = [
    {
        path: "/admin",
        component: index,
        meta: {
            name: "超级管理员",
            icon: "el-icon-menu",
            roles: "1"
        },
        children: [
            {
                path: "",
                component: admin
            }
        ]
    },
    {
        path: "/user",
        component: index,
        meta: {
            name: "用户",
            icon: "el-icon-s-custom",
            roles: "1"
        },
        children: [
            {
                path: "",
                redirect: "/profile"
            },
            {
                path: "/profile",
                component: profile,
                meta: {
                    name: "用户信息",
                    icon: "el-icon-s-custom"
                }
            },
            {
                path: "/setuser",
                component: setUser,
                meta: {
                    name: "用户管理",
                    icon: "el-icon-s-help"
                }
            }
        ]
    }
]

export const routes = [
    {
        path: "/",
        component: index,
        hidden: false,
        meta: {
            name: "首页",
            icon: "el-icon-menu"
        },
        children: [
            {
                path: "",
                component: chart
            }
        ]
    },
    {
        path: "/brand",
        component: index,
        hidden: false,
        meta: {
            name: "商品",
            icon: "el-icon-s-shop"
        },
        children: [
            {
                path: "",
                redirect: "/huili"
            },
            {
                path: "/shoplist",
                component: shoplist,
                meta: {
                    name: "商品列表",
                    icon: "el-icon-s-shop"
                }
            },
            {
                path: "/setshop",
                component: setshop,
                meta: {
                    name: "商品管理",
                    icon: "el-icon-s-shop"
                }
            },
        ]
    },
]

const whiteRoutes = [
    {
        path: "/login",
        component: login
    },
    {
        path: "*",
        component: page404
    }
]
const router = new VueRouter({
    mode: "history",
    routes: routes.concat(whiteRoutes)
})



export default router; 